package com.github.laozhaishaozuo.asm;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;

public class UserGetterDump implements Opcodes {

	public static byte[] dump() throws Exception {

		ClassWriter cw = new ClassWriter(0);
		FieldVisitor fv;
		MethodVisitor mv;
		AnnotationVisitor av0;

		cw.visit(V1_8, ACC_PUBLIC + ACC_SUPER, "com/github/laozhaishaozuo/asm/UserGetter", null, "java/lang/Object",
				new String[]{"com/github/laozhaishaozuo/asm/Getter"});

		cw.visitSource("UserGetter.java", null);

		{
			mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
			mv.visitCode();
			Label l0 = new Label();
			mv.visitLabel(l0);
			mv.visitLineNumber(7, l0);
			mv.visitVarInsn(ALOAD, 0);
			mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);
			mv.visitInsn(RETURN);
			Label l1 = new Label();
			mv.visitLabel(l1);
			mv.visitLocalVariable("this", "Lcom/github/laozhaishaozuo/asm/UserGetter;", null, l0, l1, 0);
			mv.visitMaxs(1, 1);
			mv.visitEnd();
		}
		{
			mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "call",
					"(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", null, null);
			mv.visitCode();
			Label l0 = new Label();
			mv.visitLabel(l0);
			mv.visitLineNumber(10, l0);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
			mv.visitVarInsn(ISTORE, 2);
			Label l1 = new Label();
			mv.visitLabel(l1);
			mv.visitLineNumber(11, l1);
			mv.visitVarInsn(ALOAD, 0);
			mv.visitTypeInsn(CHECKCAST, "com/github/laozhaishaozuo/asm/User");
			mv.visitVarInsn(ASTORE, 3);
			Label l2 = new Label();
			mv.visitLabel(l2);
			mv.visitLineNumber(12, l2);
			mv.visitVarInsn(ILOAD, 2);
			Label l3 = new Label();
			Label l4 = new Label();
			Label l5 = new Label();
			Label l6 = new Label();
			Label l7 = new Label();
			mv.visitTableSwitchInsn(1, 4, l7, new Label[]{l3, l4, l5, l6});
			mv.visitLabel(l3);
			mv.visitLineNumber(14, l3);
			mv.visitFrame(Opcodes.F_APPEND, 2, new Object[]{Opcodes.INTEGER, "com/github/laozhaishaozuo/asm/User"}, 0,
					null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getName", "()Ljava/lang/String;",
					false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l4);
			mv.visitLineNumber(16, l4);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getAddress",
					"()Ljava/lang/String;", false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l5);
			mv.visitLineNumber(18, l5);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getNumbers", "()I", false);
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l6);
			mv.visitLineNumber(20, l6);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getBirthDate",
					"()Ljava/util/Date;", false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l7);
			mv.visitLineNumber(22, l7);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitInsn(ACONST_NULL);
			mv.visitInsn(ARETURN);
			Label l8 = new Label();
			mv.visitLabel(l8);
			mv.visitLocalVariable("bean", "Ljava/lang/Object;", null, l0, l8, 0);
			mv.visitLocalVariable("attrName", "Ljava/lang/String;", null, l0, l8, 1);
			mv.visitLocalVariable("hash", "I", null, l1, l8, 2);
			mv.visitLocalVariable("user", "Lcom/github/laozhaishaozuo/asm/User;", null, l2, l8, 3);
			mv.visitMaxs(1, 4);
			mv.visitEnd();
		}
		{
			mv = cw.visitMethod(ACC_PUBLIC + ACC_STATIC, "callByName",
					"(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", null, null);
			mv.visitCode();
			Label l0 = new Label();
			mv.visitLabel(l0);
			mv.visitLineNumber(27, l0);
			mv.visitVarInsn(ALOAD, 0);
			mv.visitTypeInsn(CHECKCAST, "com/github/laozhaishaozuo/asm/User");
			mv.visitVarInsn(ASTORE, 2);
			Label l1 = new Label();
			mv.visitLabel(l1);
			mv.visitLineNumber(28, l1);
			mv.visitVarInsn(ALOAD, 1);
			mv.visitInsn(DUP);
			mv.visitVarInsn(ASTORE, 3);
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "hashCode", "()I", false);
			Label l2 = new Label();
			Label l3 = new Label();
			Label l4 = new Label();
			Label l5 = new Label();
			Label l6 = new Label();
			mv.visitLookupSwitchInsn(l6, new int[]{-2000515510, -1210031859, -1147692044, 3373707},
					new Label[]{l2, l3, l4, l5});
			mv.visitLabel(l2);
			mv.visitFrame(Opcodes.F_APPEND, 2, new Object[]{"com/github/laozhaishaozuo/asm/User", "java/lang/String"},
					0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitLdcInsn("numbers");
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
			Label l7 = new Label();
			mv.visitJumpInsn(IFNE, l7);
			mv.visitJumpInsn(GOTO, l6);
			mv.visitLabel(l3);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitLdcInsn("birthDate");
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
			Label l8 = new Label();
			mv.visitJumpInsn(IFNE, l8);
			mv.visitJumpInsn(GOTO, l6);
			mv.visitLabel(l4);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitLdcInsn("address");
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
			Label l9 = new Label();
			mv.visitJumpInsn(IFNE, l9);
			mv.visitJumpInsn(GOTO, l6);
			mv.visitLabel(l5);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 3);
			mv.visitLdcInsn("name");
			mv.visitMethodInsn(INVOKEVIRTUAL, "java/lang/String", "equals", "(Ljava/lang/Object;)Z", false);
			Label l10 = new Label();
			mv.visitJumpInsn(IFNE, l10);
			mv.visitJumpInsn(GOTO, l6);
			mv.visitLabel(l10);
			mv.visitLineNumber(30, l10);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 2);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getName", "()Ljava/lang/String;",
					false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l9);
			mv.visitLineNumber(32, l9);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 2);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getAddress",
					"()Ljava/lang/String;", false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l7);
			mv.visitLineNumber(34, l7);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 2);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getNumbers", "()I", false);
			mv.visitMethodInsn(INVOKESTATIC, "java/lang/Integer", "valueOf", "(I)Ljava/lang/Integer;", false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l8);
			mv.visitLineNumber(36, l8);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitVarInsn(ALOAD, 2);
			mv.visitMethodInsn(INVOKEVIRTUAL, "com/github/laozhaishaozuo/asm/User", "getBirthDate",
					"()Ljava/util/Date;", false);
			mv.visitInsn(ARETURN);
			mv.visitLabel(l6);
			mv.visitLineNumber(38, l6);
			mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
			mv.visitInsn(ACONST_NULL);
			mv.visitInsn(ARETURN);
			Label l11 = new Label();
			mv.visitLabel(l11);
			mv.visitLocalVariable("bean", "Ljava/lang/Object;", null, l0, l11, 0);
			mv.visitLocalVariable("attrName", "Ljava/lang/String;", null, l0, l11, 1);
			mv.visitLocalVariable("user", "Lcom/github/laozhaishaozuo/asm/User;", null, l1, l11, 2);
			mv.visitMaxs(2, 4);
			mv.visitEnd();
		}
		cw.visitEnd();

		return cw.toByteArray();
	}
}
